{extend name="Base/base"/}
{block name="body"}
    <div class="main-title">
        <h2>
            {:lang('_MENU_ADD_OR_EDIT_')}
        </h2>
    </div>

<div class="with-padding">


    <div class="tab-wrap" style="margin-bottom: 5px">
        <ul class="nav nav-secondary group_nav">
        </ul>
    </div>
    {notempty name="list"}
    <form action="{:url(request()->action(),array('action'=>'add'))}" method="post" class="form-horizontal">
        <label class="item-label">编号    </label>
        <div class="controls ">
            <input {notempty name="list"}type="text"{else/}type="hidden"{/notempty} name="id" value="{$list.id}"
            class="text input-large form-control" style="width:400px" placeholder="无需填写" readonly="">
            <p class="lead"></p>
        </div>
        <label class="item-label">分类名称    </label>
        <div class="controls ">
            <input type="text" name="title" value="{$list.title}" class="text input-large form-control" style="width:
            400px"></div>
        <label class="item-label">分类简介    </label>
        <div class="controls ">
            <textarea type="text" name="content" value="{$list.content}" class="text input-large form-control"
                      style="width: 400px">{$list.content}</textarea>
        </div>
        <label class="item-label">菜单小图标    </label>
        <div class="controls ">
            <div class="controls">
                <div id="upload_single_image_image" style="padding-bottom: 5px;" class="webuploader-container">
                    <div class="webuploader-pick">选择图片</div>
                    <div id="rt_rt_1b4t64277n7iv2s1e3vg7d1rtu1" style="position: absolute; top: 0px; left: 0px; width: 64px; height: 28px; overflow: hidden; bottom: auto; right: auto;">
                    <input type="file" class="webuploader-element-invisible" multiple="multiple"
                           accept="image/*">
                    <label style="opacity: 0; width: 100%; height: 100%; display: block; cursor: pointer; background: rgb(255, 255, 255);"></label>
                    </div>
                </div>
                <input class="attach" type="hidden" name="image" value="{$list.image_id}">
                <div class="upload-img-box">
                    <div class="upload-pre-item popup-gallery">
                        <div class="each">
                            <a><img src="{$list.image}"></a>
                            <div class="text-center opacity del_btn"></div>
                            <div onclick="admin_image.removeImage($(this),{$list.id})" class="text-center del_btn">删除
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--上传文件-->
            <script>
                $(function () {
                    var uploader_image= WebUploader.create({
                        // 选完文件后，是否自动上传。
                        auto: true,
                        // swf文件路径
                        swf: "__ROOT__js/ext/webuploader/js/Uploader.swf",
                        // 文件接收服务端。
                        server: "{:url('shop/upload')}",
                        // 选择文件的按钮。可选。
                        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                        pick: '#upload_single_image_image',
                        // 只允许选择图片文件
                        accept: {
                            title: 'Images',
                            extensions: 'gif,jpg,jpeg,bmp,png',
                            mimeTypes: 'image/*'
                        }
                    });
                    uploader_image.on('fileQueued', function (file) {
                        uploader_image.upload();
                    });
                    /*上传成功**/
                    uploader_image.on('uploadSuccess', function (file, data) {

                        if (data.status) {
                            $("[name='image']").val(data.id);
                            $("[name='image']").parent().find('.upload-pre-item').html(
                                '<div class="each"><a href="'+ data.url+'" disabled="true" title="点击查看大图"><img src="'+
                                data.url+'"></a><div class="text-center opacity del_btn" ></div>' +
                                '<div onclick="admin_image.removeImage($(this),'+data.id+')"  class="text-center del_btn">删除</div></div>');
                            uploader_image.reset();
                        } else {
                            updateAlert(data.info);
                            setTimeout(function () {
                                $('#top-alert').find('button').click();
                                $(that).removeClass('disabled').prop('disabled', false);
                            }, 1500);
                        }
                    });
                })
            </script>
        </div>
        <label class="item-label">banner图    </label>
        <div class="controls ">
            <div class="controls">
                <div id="upload_single_image_image1" style="padding-bottom: 5px;" class="webuploader-container">
                    <div class="webuploader-pick">选择图片</div>
                    <div id="rt_rt_1b4t64277n7iv2s1e3vg7d1rtu1" style="position: absolute; top: 0px; left: 0px; width: 64px; height: 28px; overflow: hidden; bottom: auto; right: auto;">
                        <input type="file" class="webuploader-element-invisible" multiple="multiple"
                               accept="image/*">
                        <label style="opacity: 0; width: 100%; height: 100%; display: block; cursor: pointer; background: rgb(255, 255, 255);"></label>
                    </div>
                </div>
                <input class="attach" type="hidden" name="banner" value="{$list.banner_id}">
                <div class="upload-img-box">
                    <div class="upload-pre-item popup-gallery">
                        <div class="each">
                            <a><img src="{$list.banner}"></a>
                            <div class="text-center opacity del_btn"></div>
                            <div onclick="admin_image.removeImage($(this),{$list.id})" class="text-center del_btn">删除
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--上传文件-->
            <script>
                $(function () {
                    var uploader_image= WebUploader.create({
                        // 选完文件后，是否自动上传。
                        auto: true,
                        // swf文件路径
                        swf: "__ROOT__js/ext/webuploader/js/Uploader.swf",
                        // 文件接收服务端。
                        server: "{:url('shop/upload')}",
                        // 选择文件的按钮。可选。
                        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                        pick: '#upload_single_image_image1',
                        // 只允许选择图片文件
                        accept: {
                            title: 'Images',
                            extensions: 'gif,jpg,jpeg,bmp,png',
                            mimeTypes: 'image/*'
                        }
                    });
                    uploader_image.on('fileQueued', function (file) {
                        uploader_image.upload();
                    });
                    /*上传成功**/
                    uploader_image.on('uploadSuccess', function (file, data) {

                        if (data.status) {
                            $("[name='banner']").val(data.id);
                            $("[name='banner']").parent().find('.upload-pre-item').html(
                                '<div class="each"><a href="'+ data.url+'" disabled="true" title="点击查看大图"><img src="'+
                                data.url+'"></a><div class="text-center opacity del_btn" ></div>' +
                                '<div onclick="admin_image.removeImage($(this),'+data.id+')"  class="text-center del_btn">删除</div></div>');
                            uploader_image.reset();
                        } else {
                            updateAlert(data.info);
                            setTimeout(function () {
                                $('#top-alert').find('button').click();
                                $(that).removeClass('disabled').prop('disabled', false);
                            }, 1500);
                        }
                    });
                })
            </script>
        </div>
        <label class="item-label">上级分类    </label>
        <div class="controls ">
            <select name="parent_id" class="form-control" style="width:auto;">
                <option value="0">顶级分类</option>
                {foreach name="tag" item="c"}
                {if condition="$list['parent_id'] eq $c['id']"}
                <option value="{$c.id}" selected="">{$c.title}&nbsp;</option>
                {else/}
                <option value="{$c.id}">{$c.title}&nbsp;</option>
                {/if}
                {/foreach}

            </select>
        </div>
        <label class="item-label">排序    </label>
        <div class="controls ">
            <input type="text" name="sort" value="{$list.sort}" class="text input-large form-control" style="width: 400px"></div>
        <label class="item-label">状态    </label>
        <div class="controls ">
            <label for="id_stauts_0"><input id="id_stauts_0" name="status" value="0" type="radio" {if condition="$list.status==0"}checked=""{/if}>正常</label>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <label for="id_stauts_1"> <input id="id_stauts_1" name="status" value="1" type="radio" {if
                                             condition="$list.status==1"}checked=""{/if}>隐藏</label>
            &nbsp;&nbsp;&nbsp;&nbsp;</div>
        <label class="item-label">创建时间    </label>
        <div class="controls ">
            {notempty name="list.create_time"}
            <input type="hidden" name="create_time" value="{$list.create_time}">
            <input type="text" id="datetimepicker" data-field-name="create_time"
                   class="text input-large form-datetime time form-control" style="width: 400px"
                   value="{$list.create_time}"
                   placeholder="请选择时间">
            {else/}
            <input type="hidden" name="create_time" value="<?php echo time()?>">
            <input type="text" id="datetimepicker" data-field-name="create_time"
                   class="text input-large form-datetime time form-control" style="width: 400px"
                   value="<?php echo time_format(time())?>"
                   placeholder="请选择时间">
            {/notempty}
        </div>
        <br>

        <div class="form-item">
            <button class="btn  ajax-post btn-success" id="submit" type="submit" target-form="form-horizontal">确定
            </button>  &nbsp;<button onclick="javascript:history.back(-1);return false;" class="btn btn-return">返回</button>  &nbsp;            </div>
    </form>
    {else/}
    <form action="{:url(request()->action(),array('action'=>'add'))}" method="post" class="form-horizontal">
        <label class="item-label">编号    </label>
        <div class="controls ">
            <input type="hidden" name="id" value="" class="text input-large form-control" style="width:400px" placeholder="无需填写" readonly="">
            <p class="lead"></p>
        </div>
        <label class="item-label">分类名称    </label>
        <div class="controls ">
            <input type="text" name="title" value="" class="text input-large form-control" style="width:
            400px"></div>
        <label class="item-label">分类简介    </label>
        <div class="controls ">
            <textarea type="text" name="content" value="" class="text input-large form-control"
                      style="width: 400px"></textarea>
        </div>
        <label class="item-label">菜单小图标    </label>
        <div class="controls ">
            <div class="controls">
                <div id="upload_single_image_image" style="padding-bottom: 5px;" class="webuploader-container">
                    <div class="webuploader-pick">选择图片</div>
                    <div id="rt_rt_1b4t64277n7iv2s1e3vg7d1rtu1" style="position: absolute; top: 0px; left: 0px; width: 64px; height: 28px; overflow: hidden; bottom: auto; right: auto;">
                        <input type="file" name="file" class="webuploader-element-invisible" multiple="multiple"
                               accept="image/*">
                        <label style="opacity: 0; width: 100%; height: 100%; display: block; cursor: pointer; background: rgb(255, 255, 255);"></label>
                    </div>
                </div>
                <input class="attach" type="hidden" name="image" value="">
                <div class="upload-img-box">
                    <div class="upload-pre-item popup-gallery">

                    </div>
                </div>
            </div>
            <!--上传文件-->
            <script>
                $(function () {
                    var uploader_image= WebUploader.create({
                        // 选完文件后，是否自动上传。
                        auto: true,
                        // swf文件路径
                        swf: "__ROOT__js/ext/webuploader/js/Uploader.swf",
                        // 文件接收服务端。
                        server: "{:url('shop/upload')}",
                        // 选择文件的按钮。可选。
                        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                        pick: '#upload_single_image_image',
                        // 只允许选择图片文件
                        accept: {
                            title: 'Images',
                            extensions: 'gif,jpg,jpeg,bmp,png',
                            mimeTypes: 'image/*'
                        }
                    });
                    uploader_image.on('fileQueued', function (file) {
                        uploader_image.upload();
                    });
                    /*上传成功**/
                    uploader_image.on('uploadSuccess', function (file, data) {

                        if (data.status) {
                            $("[name='image']").val(data.id);
                            $("[name='image']").parent().find('.upload-pre-item').html(
                                '<div class="each"><a href="'+ data.url+'" disabled="true" title="点击查看大图"><img src="'+
                                data.url+'"></a><div class="text-center opacity del_btn" ></div>' +
                                '<div onclick="admin_image.removeImage($(this),'+data.id+')"  class="text-center del_btn">删除</div></div>');
                            uploader_image.reset();
                        } else {
                            updateAlert(data.info);
                            setTimeout(function () {
                                $('#top-alert').find('button').click();
                                $(that).removeClass('disabled').prop('disabled', false);
                            }, 1500);
                        }
                    });
                })
            </script>
        </div>
        <label class="item-label">banner图    </label>
        <div class="controls ">
            <div class="controls">
                <div id="upload_single_image_image1" style="padding-bottom: 5px;" class="webuploader-container">
                    <div class="webuploader-pick">选择图片</div>
                    <div id="rt_rt_1b4t64277n7ig7d1rtu1" style="position: absolute; top: 0px; left: 0px; width: 64px; height: 28px; overflow: hidden; bottom: auto; right: auto;">
                        <input type="file" name="file1" class="webuploader-element-invisible" multiple="multiple"
                               accept="image/*">
                        <label style="opacity: 0; width: 100%; height: 100%; display: block; cursor: pointer; background: rgb(255, 255, 255);"></label>
                    </div>
                </div>
                <input class="attach" type="hidden" name="banner" value="">
                <div class="upload-img-box">
                    <div class="upload-pre-item popup-gallery">

                    </div>
                </div>
            </div>
            <!--上传文件-->
            <script>
                $(function () {
                    var uploader_image= WebUploader.create({
                        // 选完文件后，是否自动上传。
                        auto: true,
                        // swf文件路径
                        swf: "__ROOT__js/ext/webuploader/js/Uploader.swf",
                        // 文件接收服务端。
                        server: "{:url('shop/upload')}",
                        // 选择文件的按钮。可选。
                        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                        pick: '#upload_single_image_image1',
                        // 只允许选择图片文件
                        accept: {
                            title: 'Images',
                            extensions: 'gif,jpg,jpeg,bmp,png',
                            mimeTypes: 'image/*'
                        }
                    });
                    uploader_image.on('fileQueued', function (file) {
                        uploader_image.upload();
                    });
                    /*上传成功**/
                    uploader_image.on('uploadSuccess', function (file, data) {

                        if (data.status) {
                            $("[name='banner']").val(data.id);
                            $("[name='banner']").parent().find('.upload-pre-item').html(
                                '<div class="each"><a href="'+ data.url+'" disabled="true" title="点击查看大图"><img src="'+
                                data.url+'"></a><div class="text-center opacity del_btn" ></div>' +
                                '<div onclick="admin_image.removeImage($(this),'+data.id+')"  class="text-center del_btn">删除</div></div>');
                            uploader_image.reset();
                        } else {
                            updateAlert(data.info);
                            setTimeout(function () {
                                $('#top-alert').find('button').click();
                                $(that).removeClass('disabled').prop('disabled', false);
                            }, 1500);
                        }
                    });
                })
            </script>
        </div>
        <label class="item-label">上级分类    </label>
        <div class="controls ">
            <select name="parent_id" class="form-control" style="width:auto;">
                <option value="0" selected="">顶级分类</option>
                {foreach name="tag" item="c"}
                <option value="{$c.id}">{$c.title}&nbsp;</option>
                {/foreach}
            </select>
        </div>
        <label class="item-label">排序    </label>
        <div class="controls ">
            <input type="text" name="sort" value="" class="text input-large form-control" style="width: 400px"></div>
        <label class="item-label">状态    </label>
        <div class="controls ">
            <label for="id_stauts_0"><input id="id_stauts_0" name="status" value="0" type="radio" checked="">正常</label>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <label for="id_stauts_1"> <input id="id_stauts_1" name="status" value="1" type="radio">隐藏</label>
            &nbsp;&nbsp;&nbsp;&nbsp;</div>
        <label class="item-label">创建时间    </label>
        <div class="controls ">
            <input type="hidden" name="create_time" value="<?php echo time()?>">
            <input type="text" id="datetimepicker" data-field-name="create_time"
                   class="text input-large form-datetime time form-control" style="width: 400px"
                   value="<?php echo time_format(time())?>"
                   placeholder="请选择时间">
        </div>
        <br>

        <div class="form-item">
            <button class="btn ajax-post btn-success" id="submit" type="submit" target-form="form-horizontal">确定</button>  &nbsp;<button onclick="javascript:history.back(-1);return false;" class="btn btn-return">返回</button>  &nbsp;            </div>
    </form>
    {/notempty}
</div>
{/block}

{block name="script"}
    <script type="text/javascript">
        $('#datetimepicker').datetimepicker({
            language: "zh-CN",
            autoclose: true,
            format: 'yyyy-mm-dd hh:ii'
        });
        $(function () {
            //搜索功能
            $("#search").click(function () {
                var url = $(this).attr('url');
                var query = $('.search-form').find('input').serialize();
                query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
                query = query.replace(/^&/g, '');
                if (url.indexOf('?') > 0) {
                    url += '&' + query;
                } else {
                    url += '?' + query;
                }
                window.location.href = url;
            });
            //回车搜索
            $(".search-input").keyup(function (e) {
                if (e.keyCode === 13) {
                    $("#search").click();
                    return false;
                }
            });
            //导航高亮

            //点击排序
            $('.list_sort').click(function () {
                var url = $(this).attr('url');
                var ids = $('.ids:checked');
                var param = '';
                if (ids.length > 0) {
                    var str = new Array();
                    ids.each(function () {
                        str.push($(this).val());
                    });
                    param = str.join(',');
                }

                if (url != undefined && url != '') {
                    window.location.href = url + '/ids/' + param;
                }
            });
        });
    </script>
{/block}